package com.ysxsoft.wdg.ui.activity.my;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.BaseBean;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.sp.SharePrefUtils;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ModifySexActivity extends BaseActivity {

    public static void start(Context context, int sex){
        Intent intent = new Intent(context,ModifySexActivity.class);
        intent.putExtra("sex",sex);
        context.startActivity(intent);
    }

    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_finish)
    ImageView titleFinish;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_tv_r)
    TextView titleTvR;
    @BindView(R.id.tv_nv)
    TextView tvNv;
    @BindView(R.id.tv_nan)
    TextView tvNan;

    private int sex = 0;//0男1女
    private String uid = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_sex;
    }

    @Override
    protected void initData() {
        initStatusBar(topView,false);
        titleContent.setText("修改性别");
        titleTvR.setText("保存");

        uid = SharePrefUtils.getUserId();


        sex = getIntent().getIntExtra("sex",0);
        if (sex == 0){
            tvNan.setSelected(true);
        }else {
            tvNv.setSelected(true);
        }

    }

    @Override
    protected void setListener() {

    }


    @OnClick({R.id.title_finish, R.id.title_tv_r, R.id.tv_nv, R.id.tv_nan})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.title_tv_r:
                mApiHelper.modifyPersonInfo(uid, "", "", sex+"", "", "", "", new Observer<BaseBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BaseBean baseBean) {
                        ToastUtils.showToast(baseBean.getMs());
                        if (baseBean.getCode().equals(CallbackCode.SUCCESS)){
                            finish();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
                break;
            case R.id.tv_nv:// 	0男1女
                sex = 1;
                tvNv.setSelected(true);
                tvNan.setSelected(false);
                break;
            case R.id.tv_nan:
                sex =0;
                tvNv.setSelected(false);
                tvNan.setSelected(true);
                break;
        }
    }
}
